<!DOCTYPE html>
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<html class="win-frame">
<head>
<title>组织机构管理-新建组织机构</title>
<%@include file="/common/head.jsp" %>
<%@include file="/common/taglibs.jsp" %>
<link href="<%=request.getContextPath()%>/static/styles/css/region.css" rel="stylesheet">
<script src="<%=request.getContextPath()%>/static/plugin/JSpinyin/JSpinyin.js"></script>
<script src="<%=request.getContextPath()%>/static/js/region.js"></script>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>组织机构管理</span>
            <span class="split"></span>
            <span>新建组织机构</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="orgForm" method="post">
	<div id="left" style="width:80%;float:left">
		<div class="form-wrapper">
			<div class="form-cont">
		        <p class="form-cont-title"><span class="field-required">*</span>上级机构名称</p>
		        <input type="hidden" name="pCode" value="${parentOrg.code }"/> 
			    <input type="text"  class="summer-input" readonly="readonly" value="${empty parentOrg.name? '无' : parentOrg.name }"/>
		        <input type="hidden" id="regionId" name="regionId"/>
		        <input type="hidden" id="regionCode" name="regionCode"/>
		     </div>
		     
		     <div class="form-cont">
		        <p class="form-cont-title"><span class="field-required">*</span>机构名称</p>
		        <input type="text" id="name" name="name" class="summer-input summer-validatebox" data-validatebox="validType:['required','chsNoSymbol','maxLength[100]']"/>
		     </div>
		     
		     <div class="form-cont">
		        <p class="form-cont-title"><span class="field-required">*</span>行政区划</p>
		        <input type="text" id="regionName" readonly="readonly" class="summer-input summer-validatebox distance-right" data-validatebox="validType:['required']"/>
		     </div>
		     
		     <div class="form-cont">
		        <p class="form-cont-title">名称简称</p>
		        <input type="text" id="sName" name="sName" class="summer-input summer-validatebox" data-validatebox="validType:['chsNoSymbol','maxLength[50]']"/>
		     </div>
		     
		     <div class="form-cont">
		        <p class="form-cont-title"><span class="field-required">*</span>机关类型</p>
		        <input type="text" id="type" name="type" class="summer-input summer-validatebox" data-validatebox="validType:['required']"/>
		     </div>
		     
		     <div class="form-cont">
		        <p class="form-cont-title"><span class="field-required">*</span>机构类别</p>
		        <input type="text" id="clazz" name="clazz" class="summer-input summer-validatebox" data-validatebox="validType:['required']"/>
		        <label class="label-secondary "></label>
		     </div>
		     
		     <div class="form-cont">
		        <p class="form-cont-title">机构地址</p>
		        <input type="text" id="address" name="address" class="summer-input summer-validatebox" data-validatebox="validType:['maxLength[200]']"/>
		     </div>
		     
		     <div class="form-cont">
		        <p class="form-cont-title">机构电话</p>
		        <input type="text" id="tel" name="tel" class="summer-input summer-validatebox" data-validatebox="validType:['phone']"/>
		     </div>
		     
		      <div class="form-cont">
		        <p class="form-cont-title">机构传真</p>
		        <input type="text" id="fax" name="fax" class="summer-input summer-validatebox" data-validatebox="validType:['fax']"/>
		     </div>
		     
		      <div class="form-cont">
		        <p class="form-cont-title"><span class="field-required">*</span>排序号</p>
		        <input type="text" id="orderNo" name="orderNo" class="summer-input summer-validatebox" data-validatebox="validType:['required','betweenInteger[1,100000]']"/>
		     </div>
		   </div>
		   
		   <div class="form-btn-wrapper">
		    <a class="btn btn-normal btn-ok distance-right" id="saveBtn">保存</a>
		    <a class="btn btn-normal btn-ok" id="saveContinueBtn">保存并继续</a>
		   </div>
	</div>  
</form>

<script>
	$(function() {
		//初始化机关类型
		initCombobox('type', COMMON_URL.getCode + '?type=T_DM_ORG_TYPE');
		
		//初始化机构类别
		initCombobox('clazz', COMMON_URL.getCode + '?type=T_DM_ORG_CLAZZ', '${parentOrg.clazz}');
		
		//点击查看行政区划
		$('#regionName').region({
            width:700,	//窗口宽度
            height:450,	//窗口高度
            rootId:'0',	//根节点
            level:1,//需要拼音分组的层级
            onselect:function(obj){
            	$('#regionId').val(obj.attr('data-id'));
            	$('#regionCode').val(obj.attr('data-code'));
            	$('#regionName').focus();
            }
		});
		
		//保存按钮操作
		$('#saveBtn').on('click',{isContinue: false}, save);
		
		//保存并继续
		$('#saveContinueBtn').on('click',{isContinue: true}, save);
		
		//返回上级
		$('#goBack').on('click', function () {
			parent.refreshList('${parentOrg.code}');
		});
	});
	
	
	//初始化combobox
	function initCombobox(id, url, defaultValue, async, menuHeight) {
		$('#' + id).combobox({
            valueField: 'code',
            textField: 'name',
            async: async? async: false,
            url: url,
            defaultValue: defaultValue,
            menuHeight: menuHeight? menuHeight: 'auto'
        });
	}
	
	//保存操作
    function save(event) {
        $('#orgForm').form({
        	buttons : ['#saveBtn','#saveContinueBtn'],
            ajax: {
                url: ORG_CONST_URL.ADD
            },
            onSubmitSuccess: function (data) {
            	 $.stip({
 	                type:'ok',//显示类型 有info、 ok、 danger
 	                text: '保存成功！',
 	                onBeforeHide: function () {
 	            	  var isContinue = event.data.isContinue;
                  	  if (isContinue) {
                         parent.refreshList('${parentOrg.code}', isContinue);
                         resetForm();
                  	  } else {
                  		parent.refreshList('${parentOrg.code}');
                  	  }
 	               }
             	});
            }
        }).form("submit");
    }
	
	//保存并继续清空form
    function resetForm(){
        $("#regionId,#regionCode,#regionName,#name,#address,#tel,#fax,#orderNo,#sName").val("");
        $('#type').combobox("clear");
        $('#clazz').combobox("setValue", '${parentOrg.clazz}');
    }
	
	
	var ORG_CONST_URL = {
		ADD: basePath + "/sys/org/add"
	};
</script>
</body>
</html>
